﻿using Centny.PdfReader.IO;
using Centny.PdfReader.Types;
using Centny.PdfReader.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Centny.PdfReader.Operator
{
    public class PdfCtm : PdfOperatorExecuter
    {

        public PdfStreamLexer Lexer
        {
            get;
            set;
        }

        public string Operator
        {
            get { return "cm"; }
        }

        public virtual void Execute(Types.PdfOperator op)
        {
            PdfMatrix m = new PdfMatrix();
            if (op.Args.Count < 6)
            {
                throw new InvalidOperationException("invalid cm opertaor arguments");
            }

            m[0][0] = (op.Args[0] as PdfDouble).Val;
            m[0][1] = (op.Args[1] as PdfDouble).Val;
            m[1][0] = (op.Args[2] as PdfDouble).Val;
            m[1][1] = (op.Args[3] as PdfDouble).Val;
            m[2][0] = (op.Args[4] as PdfDouble).Val;
            m[2][1] = (op.Args[5] as PdfDouble).Val;
            m.Multiply(this.Lexer.GraphicsState.Ctm, m);
            this.Lexer.SetCtm(m);
        }
    }
}
